﻿<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<body class="easyui-layout">
<!-- 遮罩层 -->
<div id='PageLoadingTip' style="position: absolute; z-index: 1000; top: 0px; left: 0px; width: 100%; height: 100%; background: #222222; text-align: center;">
    <h1 style="top: 48%; position: relative"><img src="/media/image/loading.gif"></h1>
</div>
<div data-options="region:'center',border:false" style="padding:2px;height: auto">
	<table id="role_list_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
		   data-options="
		   	 rownumbers:true,
		   	 pagination:true,
		   	 singleSelect:true,
		   	 toolbar : '#tb',
		   	 fitColumns : true,
		   	 url:'/button-list-json/1/20',
           method:'get',
           onAfterEdit:function(index,row){
           	var buttonName = row.buttonName;
           	var menuName = row.menuName;
           	var buttonRemark = row.buttonRemark;
           	var id = row.id;
           	var menuID = row.menuID;
           	var buttonId = row.buttonId;
           	var iconCls = row.iconCls;
				updateActions(buttonName,buttonRemark,menuName,id,menuID,buttonId,iconCls);
			 },
           showFooter: true"
		>
		<thead>
		<tr>
			<th data-options="field:'id',width:90,align:'center'" hidden></th>
			<th data-options="field:'menuID',width:90,align:'center'" hidden></th>
			<th data-options="field:'menuName',width:90,align:'center',
					editor:{
						type:'validatebox',
						options:{
							required:true,
							missingMessage:'请输入显示名称'
						}
					}">按钮名称</th>
			<th data-options="field:'menuURL',width:90,align:'center'" >界面名称</th>
			<th data-options="field:'menuIcon',width:90,align:'center',
					editor:{
						type:'validatebox',
						options:{
							required:true,
							missingMessage:'请输入显示名称'
						}
					}">按钮描述</th>
		</thead>
	</table>
</div>

<div id="tb" style="padding:5px;height:auto">
	<#list buttons as buttons>
        <a href="#" class="easyui-linkbutton" iconCls="${buttons.iconCls}" id="${buttons.buttonId}">${buttons.buttonName}</a>
	</#list>
</div>

<script type="text/javascript">
    //新增
    $("#add").click(function () {
        var url = '/button-add';
        var index = layer.open({
            title:'用户添加',
            type: 2,
            area: ['700px', '450px'],
            fixed: false, //不固定
            maxmin: false,
            content: url
        });
    })

	//编辑
	$("#edit").click(function () {
		var row = $('#role_list_table').datagrid('getSelected');
		if (row){
			var index = $('#role_list_table').datagrid('getRowIndex', row);
            $('#role_list_table').datagrid('selectRow',index);
            $('#role_list_table').datagrid('beginEdit',index);
		} else {
            $.messager.show({
                title:'提示',
                msg:'请选择需要编辑的角色',
                timeout:3000,
                showType:'slide',
            });
		}
	})

	//保存
	$("#save").click(function () {
		var row = $('#role_list_table').datagrid('getSelected');
		if (row){
			var index = $('#role_list_table').datagrid('getRowIndex', row);
		} else {
			index = 0;
		}
		$('#role_list_table').datagrid('endEdit',index);
	})



	//删除
	$("#delete").click(function () {
		var row = $('#role_list_table').datagrid('getSelected');
		if(!row){
			$.messager.show({
				title:'提示',
				msg:'请选择需要删除的角色',
				timeout:3000,
				showType:'slide',
			});
		}else{
			$.messager.confirm('删除信息','确定删除用户:'+row.roleName+"吗?",function(r){
				if (r){
					$.ajax({
						url : '/button-ins-upd-del/d',
						data : {id : row.id},
						async : true,
						success : function(){
							$('#role_list_table').datagrid('reload');
						}
					});
				}
			});
		}
	})
</script>
<script>
	function updateActions(buttonName,buttonRemark,menuName,id,menuID,buttonId,iconCls){
		var url = '/button-ins-upd-del/';
		//修改
		if(id!=null&&id!=''){
			url += 'u';
		}else{
		    url += 'i'
		}
		$.ajax({
			url : url,
			data : {buttonName : buttonName,buttonRemark:buttonRemark,id : id,menuName:menuName,menuID:menuID,buttonId:buttonId,iconCls:iconCls,tm:new Date()},
			async : true,
			type : 'post',
			success :function () {
				$('#role_list_table').datagrid('reload');
			},
			error : function () {
				alert('error');
			}
		})
	}
</script>

<script type="text/javascript">
    $(function(){
        var p = $('#role_list_table').datagrid().datagrid('getPager');
        p.pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 25, 35], //可以设置每页记录条数的列表
            onSelectPage: function (pageNumber, pageSize) {
                var handler = '/button-list-json/'+pageNumber+'/'+pageSize;
                $('#role_list_table').datagrid('options').url = handler;
                $('#role_list_table').datagrid('reload');
            }
        });
    })

</script>

<!-- 遮罩层 -->
<script type="text/javascript">
    function _PageLoadingTip_Closes() {
        $("#PageLoadingTip").fadeOut("normal", function () {
            $(this).remove();
        });
    }

    var _pageloding_pc;
    $.parser.onComplete = function () {
        if (_pageloding_pc) clearTimeout(_pageloding_pc);
        _pageloding_pc = setTimeout(_PageLoadingTip_Closes, 1000);
    }
</script>